$(function() {
    var optarray = $("#upload_soal_bab").children('optgroup').map(function() {
    	var $optgroup = $(this);
        return {
            "label": this.label,
            "kelas": $optgroup.attr('kelas'),
            "optgroup": "<optgroup label='" + this.label + "' kelas='"+$optgroup.attr('kelas')+"'>"+$optgroup.html()+"</optgroup>"
        }
    })
    $("#upload_soal_kelas").change(function() {
        $("#upload_soal_bab").children('optgroup').remove();
        var addoptarr = [];
        for (i = 0; i < optarray.length; i++) {
            if (optarray[i].kelas == $(this).val()) {
                addoptarr.push(optarray[i].optgroup);
            }
        }
        if($(this).val() == ''){
        	$("#upload_soal_bab").attr('class','disabled');
	        $("#upload_soal_bab").attr('disabled',"");
    	}else{
	        $("#upload_soal_bab").removeAttr('class');
	        $("#upload_soal_bab").removeAttr('disabled');		    		
    	}
        $("#upload_soal_bab").html(addoptarr.join(''))
    }).change();
});